package com.xing.serviceedu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xing.commonutils.R;
import com.xing.serviceedu.entity.EduCourse;
import com.xing.serviceedu.entity.EduTeacher;
import com.xing.serviceedu.service.EduCourseService;
import com.xing.serviceedu.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 首页控制层
 *
 * @author: xingfuhao
 * @create: 2022-03-21 22:08
 */
@RestController
@RequestMapping("index")
@CrossOrigin
public class indexFrontController {

    @Autowired
    EduCourseService courseService;

    @Autowired
    EduTeacherService teacherService;

    //查询前8条热门课程，查询前4条名师
    @GetMapping("index")
    public R index(){

        //查询前8条热门课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> educourList = courseService.list(wrapper);

        //查询前4条名师
        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(wrapperTeacher);

        return R.ok().data("eduList",educourList).data("teacherList",teacherList);

    }

}
